<?php
    header("content-type:text/html;charset=utf-8");
    session_start();
    $config = include_once('../public/config/config.php');
    include_once('../public/func/db.php');
    $_POST['ctime'] = time();
    $arr = select($config,'user');
    if(empty($_SESSION)){
        die("<script>alert('请先登录！');window.location.href='/home/login/login.php'</script>");
    }else if(empty($_POST['reply'])){
        die("<script>alert('评论不能为空');window.location.href='/home/blog.php?id=".$_POST['aid']."'</script>");
    }
    foreach ($arr as $k => $v) {
        if($v['uname'] == $_SESSION['uname']){
            $_POST['uid'] = $v['id'];
        }
    }
    $res = insert($config,'reply',$_POST);
    if(!empty($res)){
        echo "<script>alert('评论失败');window.location.href='/home/blog.php?id=".$_POST['aid']."'</script>";
    }else{
        echo "<script>alert('评论成功');window.location.href='/home/blog.php?id=".$_POST['aid']."'</script>";
    }
?>